<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <span>
          <b class="u-f-16">代理商选择列表</b>
        </span>
        <router-link :to="{ name: 'agencyEdit' }" v-if="hasPerm('agencyEdit')">
          <el-button
            type="danger"
            size="small"
            icon="el-icon-plus"
            class="u-right u-5mt"
            round
            >添加代理商</el-button
          >
        </router-link>
      </div>

      <el-form
        :inline="true"
        :model="queryForm"
        size="small"
        class="u-text-center"
      >
        <el-form-item label="启用状态">
          <el-select v-model="queryForm.status" clearable>
            <el-option label="全部" value></el-option>
            <el-option label="启用" value="1"></el-option>
            <el-option label="未启用" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="代理商名称">
          <el-input
            v-model="queryForm.keyword"
            placeholder="输入代理商名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="getPageData(true)"
            >查询</el-button
          >
        </el-form-item>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="id" prop="id" width="100"></el-table-column>
        <el-table-column label="选择代理商" width="120">
          <template slot-scope="scope">
            <div class="table-dropdown">
              <el-button size="mini" type="text" @click="select_data(scope.row)"
                >选择</el-button
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column label="代理商图片">
          <template slot-scope="scope">
            <el-image
              style="max-width: 80px"
              :src="scope.row.agency_img"
              :data-src="scope.row.agency_img"
              fit="cover"
              lazy
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column
          label="代理商名称"
          prop="agency_title"
        ></el-table-column>
        <el-table-column
          label="代理商个人姓名"
          prop="agency_name"
        ></el-table-column>
        <el-table-column
          label="代理商账号"
          prop="agency_login_username"
        ></el-table-column>
        <el-table-column
          label="范围（Km）"
          prop="agency_range"
        ></el-table-column>
        <el-table-column label="下单数" prop="order_num"></el-table-column>
        <el-table-column label="收益总额" prop="cons_all"></el-table-column>
        <el-table-column label="收益信息" v-if="hasPerm('agencyEarnings')">
          <template slot-scope="scope">
            <el-button
              @click.native="handleRoute(scope.row.id, 'agencyEarnings')"
              v-if="hasPerm('agencyEarnings')"
              size="mini"
              type="success"
              >{{ scope.row.earnings_num }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="订单列表" v-if="hasPerm('agencyOrderList')">
          <template slot-scope="scope">
            <el-button
              @click.native="handleRoute(scope.row.id, 'agencyOrderList')"
              v-if="hasPerm('agencyOrderList')"
              size="mini"
              type="success"
              >{{ scope.row.order_num }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="代理用户" v-if="hasPerm('agencyUser')">
          <template slot-scope="scope">
            <el-button
              @click.native="handleRoute(scope.row.id, 'agencyUser')"
              v-if="hasPerm('agencyUser')"
              size="mini"
              type="success"
              >{{ scope.row.user_num }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              :inactive-value="2"
              active-color="#13ce66"
            ></el-switch>
          </template>
        </el-table-column>

        <el-table-column label="代理商地址">
          <template slot-scope="scope">
            <el-tag
              >{{ scope.row.agency_province }}-{{ scope.row.agency_city }}-{{
                scope.row.agency_county
              }}</el-tag
            >
            <br />
            <el-tag>详细地址:{{ scope.row.agency_detail_address }}</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <div class="u-mt-20 u-text-center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";
export default {
  mixins: [commonPage],
  data() {
    return {
      apiName: "agency",
      queryForm: {
        status: "",
        keyword: "",
      },
    };
  },
  methods: {
    select_data(row) {
      //选中数据
      this.$emit("user_select", row); //返回父组件
    },
  },
};
</script>
